package com.aaa.tmr.controller;

import com.aaa.tmr.entity.OperLog;
import com.aaa.tmr.service.OperLogService;
import com.aaa.tmr.util.Result;
import com.aaa.tmr.util.ReturnStatus;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 操作日志记录(OperLog)表控制层
 *
 * @author makejava
 * @since 2021-03-22 18:51:34
 */
@Controller
@RequestMapping("operLog")
public class OperLogController {
    /**
     * 服务对象
     */
    @Resource
    private OperLogService operLogService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ResponseBody
    @RequestMapping("selectOne")
    public OperLog selectOne(Integer id) {
        return this.operLogService.queryById(id);
    }

    /**
     *
     *
     * @return
     */
    @RequestMapping("toOperLog")
    public String toPage() {
        return "back/operLog-page";
    }

    /**
     * 按年月查询图标显示数据
     * @param year
     * @param month
     * @return
     */
    @ResponseBody
    @RequestMapping("queryShowChartData")
    public Result queryShowChartData(Integer year, Integer month) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.operLogService.queryShowChartData(year,month));
    }


    /**
     * 分页查询方法
     *
     * @param page
     * @param limit
     * @param operLog
     * @return
     */
    @ResponseBody
    @RequestMapping("queryAll")
    public Result queryAll(Integer page, Integer limit, OperLog operLog) {
        PageInfo pageInfo = operLogService.queryAll(page, limit, operLog);
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                pageInfo.getTotal(), pageInfo.getList());
    }


    /**
     * 部门添加
     *
     * @param operLog
     * @return
     */
    @ResponseBody
    @PostMapping("insert")
    public Result insert(OperLog operLog) {
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                0, operLogService.insert(operLog));
    }

    /**
     * 部门更新
     *
     * @param operLog
     * @return
     */
    @ResponseBody
    @PutMapping("update")
    public Result update(OperLog operLog) {
        return new Result(ReturnStatus.SUCCESS.getCode(), ReturnStatus.SUCCESS.getMessage(),
                0, operLogService.update(operLog));
    }

    /**
     * 通过主键删除数据
     *
     * @param operLogId 主键
     * @return 是否成功
     */
    @ResponseBody
    @DeleteMapping("deleteById")
    public Result deleteById(Integer operLogId) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.operLogService.deleteById(operLogId));
    }


    /**
     * 通过主键删除数据
     *
     * @param operLogIds 主键
     * @return 是否成功
     */
    @ResponseBody
    @DeleteMapping("deleteByIds")
    public Result deleteByIds(String operLogIds) {
        return new Result(ReturnStatus.SUCCESS.getCode(),
                ReturnStatus.SUCCESS.getMessage(), 0,
                this.operLogService.batchDeleteById(operLogIds));
    }


}
